package 极客算法训练营.chapter07;

import 极客算法训练营.chapter06.N叉树的后序遍历;

import java.util.List;

public class 翻转二叉树 {

    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    class Solution {
        public TreeNode invertTree(TreeNode root) {
            _invertTree(root);
            return root;
        }

        private void _invertTree(TreeNode root) {
            if (root == null) return;
            TreeNode _left = root.left;
            TreeNode _right = root.right;
            root.left = _right;
            root.right = _left;
            _invertTree(_left);
            _invertTree(_right);
        }
    }

}
